//
//  SHDetailsViewController.m
//  News
//
//  Created by dlios on 15-5-14.
//  Copyright (c) 2015年 PEAK. All rights reserved.
//

#import "SHDetailsViewController.h"

@interface SHDetailsViewController ()<UITableViewDelegate, UITableViewDataSource, UIWebViewDelegate>
@property(nonatomic, retain)UIWebView *web;
;

@property(nonatomic,retain)NSMutableArray *ArrOne;
@property(nonatomic, retain)NSMutableArray *ArrTwo;
@property(nonatomic, retain)NSDictionary *dic;
@property(nonatomic ,retain)NSArray * imgArr;


@property(nonatomic, retain) UIActivityIndicatorView *activityIndicator;
@property(nonatomic ,retain)UIImageView *imageView;
@end

@implementation SHDetailsViewController


- (void)dealloc
{
   
    [_imgArr release];
    [_web release];
    [_imageView release];
    [_activityIndicator release];
    [_imgArr release];
    [_dic release];
    [_body release];
    [_scr release];
    [_str release];
    [_strTwo release];
    [super dealloc];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
//    self.title = @"详情";
     self.automaticallyAdjustsScrollViewInsets = YES;
    self.navigationController.navigationBar.translucent = YES;
 
               //请求出现小菊花
        self.imageView  = [[UIImageView alloc] initWithFrame:self.view.bounds];
        _imageView.image = [UIImage imageNamed:@"5EA2D64D-15BE-43D8-AB18-E15BCE039C8F"];
        _imageView.alpha =0.6;
        [self.view addSubview:_imageView];
    
        _activityIndicator = [[UIActivityIndicatorView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 32.0f, 32.0f)];
        [_activityIndicator setCenter:_imageView.center];
        _activityIndicator.backgroundColor= [UIColor grayColor];
        [_activityIndicator setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhite];
        [_imageView addSubview:_activityIndicator];
    
        [_activityIndicator startAnimating];
   
    
    [self details];

}


// 数据
-(void)details{
    
    NSString *str = [NSString stringWithFormat:@"http://c.m.163.com/nc/article/%@/full.html",_strTwo];

    [SNetWorkHandle getDataWithURL:str completion:^(id result) {
        
        NSDictionary *xiangqingDic  =[result objectForKey:_strTwo];
        
        self.xiangqing = [[SHppyObject alloc] initWithDic:xiangqingDic];
        
        self.imgArr = (NSArray *)_xiangqing.img;
        
        _xiangqing.ImgArr = [NSMutableArray array];
        

        for (NSDictionary *dic in _xiangqing.img) {
            SHappyOneObject *Two = [[SHappyOneObject alloc] initWithDic:dic];
            NSString *str = [NSString stringWithFormat:@"<img width=%lf src=\"%@\">",self.view.bounds.size.width - 20,Two.src];

            _xiangqing.body = [_xiangqing.body stringByReplacingOccurrencesOfString:Two.ref withString:str];
            
        }
        
        [self create];
    }];
    
}
// 创建
-(void)create
{
    self.web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 66, self.view.frame.size.width, self.view.frame.size.height- _web.frame.size.height - 50)];
    
    [_web loadHTMLString:_xiangqing.body baseURL:nil];
    [self.view addSubview:_web];
    _web.scrollView.bounces = NO;
    _web.delegate = self;
    [_web release];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
